home *** CD-ROM | disk | FTP | other *** search
- Path: grimsel.zurich.ibm.com!usenet
- From: wgk@zurich.ibm.com (Keith Whittingham)
- Newsgroups: comp.lang.c
- Subject: Re: reversing a string
- Date: 9 Apr 1996 15:39:21 GMT
- Organization: IBM Research, ZRH
- Message-ID: <4ke0b9$rk5@grimsel.zurich.ibm.com>
- References: <4k6cjl$j8f@central.server.swt.edu> <4kb1s7$6eu@ibm32.perftech.com> <829058514snz@genesis.demon.co.uk>
- Reply-To: wgk@zurich.ibm.com
- NNTP-Posting-Host: pine.zurich.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.00
-
- Ole! (pronounced Spanishly but written 'olleh')
-
- Well here's a starter - no second variable but two recursive functions.
- Hopefully that can be reduced to one if my project can spare the time.
- (Note to manager: don't worry, just joking).
-
- #include <stdio.h>
-
- void RecRev2(char *s)
- {
- if(s[1])
- {
- if(s[2])
- {
- RecRev2(&s[1]);
- }
- s[0] ^= s[1]; s[1] ^= s[0]; s[0] ^= s[1];
- }
- }
-
- void RecRev1(char *s)
- {
- if(s && *s)
- {
- RecRev2(s);
- RecRev1(&s[1]);
- }
- }
-
- int main(int argc, char *argv)
- {
- char *s = "Hello";
- RecRev1(s);
- puts(s);
- return 0;
- }
-
-